package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataVerification;
import com.ruoyi.system.domain.vo.SysQuarterlyHeaderVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysQuarterlyHeader;
import com.ruoyi.system.service.ISysQuarterlyHeaderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 季刊头Controller
 *
 * @author ruoyi
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/system/header")
public class SysQuarterlyHeaderController extends BaseController
{
    @Autowired
    private ISysQuarterlyHeaderService sysQuarterlyHeaderService;

    /**
     * 查询季刊头列表
     @PreAuthorize("@ss.hasPermi('system:header:list')")
     */
    @GetMapping("/list")
    public TableDataInfo list(SysQuarterlyHeader sysQuarterlyHeader)
    {
        startPage();
        List<SysQuarterlyHeader> list = sysQuarterlyHeaderService.selectSysQuarterlyHeaderList(sysQuarterlyHeader);
        return getDataTable(list);
    }

    /**
     * 导出季刊头列表
     */
    @PreAuthorize("@ss.hasPermi('system:header:export')")
    @Log(title = "季刊头", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysQuarterlyHeader sysQuarterlyHeader)
    {
        List<SysQuarterlyHeader> list = sysQuarterlyHeaderService.selectSysQuarterlyHeaderList(sysQuarterlyHeader);
        ExcelUtil<SysQuarterlyHeader> util = new ExcelUtil<SysQuarterlyHeader>(SysQuarterlyHeader.class);
        util.exportExcel(response, list, "季刊头数据");
    }

    /**
     * 获取季刊头详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:header:query')")
    @GetMapping(value = "/{headerId}")
    public AjaxResult getInfo(@PathVariable("headerId") Long headerId)
    {
        return AjaxResult.success(sysQuarterlyHeaderService.selectSysQuarterlyHeaderByHeaderId(headerId));
    }

    /**
     * 新增季刊头
     */
    @DataVerification(name = "添加季刊头")
    @PreAuthorize("@ss.hasPermi('system:header:add')")
    @Log(title = "季刊头", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysQuarterlyHeader sysQuarterlyHeader)
    {
        return toAjax(sysQuarterlyHeaderService.insertSysQuarterlyHeader(sysQuarterlyHeader));
    }

    /**
     * 修改季刊头
     */
    @DataVerification(name = "修改季刊头")
    @PreAuthorize("@ss.hasPermi('system:header:edit')")
    @Log(title = "季刊头", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysQuarterlyHeader sysQuarterlyHeader)
    {
        return toAjax(sysQuarterlyHeaderService.updateSysQuarterlyHeader(sysQuarterlyHeader));
    }

    /**
     * 删除季刊头
     */
    @PreAuthorize("@ss.hasPermi('system:header:remove')")
    @Log(title = "季刊头", businessType = BusinessType.DELETE)
	@DeleteMapping("/{headerIds}")
    public AjaxResult remove(@PathVariable Long[] headerIds)
    {
        return toAjax(sysQuarterlyHeaderService.deleteSysQuarterlyHeaderByHeaderIds(headerIds));
    }


    @GetMapping("/selectSysQuarterlyDetails/{headerId}")
    public TableDataInfo selectSysQuarterlyDetails(SysQuarterlyHeader sysQuarterlyHeader)
    {
        startPage();
        List<SysQuarterlyHeaderVo> list = sysQuarterlyHeaderService.selectSysQuarterlyDetails(sysQuarterlyHeader);
        return getDataTable(list);
    }
}
